package com.bridgeQQ.client.control
{
	import com.bridgeQQ.client.constant.CommandConst;
	import com.bridgeQQ.client.constant.MenuConst;
	import com.bridgeQQ.client.events.CommandEvent;
	import com.bridgeQQ.client.view.MainPage;
	import com.bridgeQQ.client.vo.FriendType;
	
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.NativeMenuItem;
	
	public class ContextMenuManager extends BaseContextMenuManager
	{
		public function ContextMenuManager(root:InteractiveObject, def:XML)
		{
			super(root, def);
		}
		
		protected override function createMenuItem(obj:DisplayObject, def:XML):NativeMenuItem
		{
			var item:NativeMenuItem = new NativeMenuItem(def.@label);
			return item;
		}
		
		protected override function menuItemSelected(obj:DisplayObject, label:String):void
		{
			var objData:Object = obj.hasOwnProperty("data") ? obj["data"]  : null;
			switch(label)
			{
				case MenuConst.CREATE_ZU:
				    var type:FriendType = new FriendType();
				    this.mainRoot.addFriendType(type);
				    break;
				case MenuConst.DEL_ZU:
				    root.dispatchEvent(new CommandEvent(CommandEvent.COMMAND_ACTIVATE, 
				        CommandConst.DEL_FRIEND_TYPE,{item: objData}));
				    break;
				case MenuConst.DEL_FRIEND:
				    var parentData:Object = obj["parentDocument"]["data"];
				    root.dispatchEvent(new CommandEvent(CommandEvent.COMMAND_ACTIVATE, 
				        CommandConst.REMOVE_FRIEND,{item: objData, typeID: parentData.id, friend: objData.email}));
				    break;
				case MenuConst.SEND_NORMAL_MSG:
				    root.dispatchEvent(new CommandEvent(CommandEvent.COMMAND_ACTIVATE, 
				        CommandConst.OPEN_NORMAL_MSG,{friend: objData}));
				    break;
			    case MenuConst.SEND_BRIDGE_MSG:
			        root.dispatchEvent(new CommandEvent(CommandEvent.COMMAND_ACTIVATE, 
				        CommandConst.OPEN_BRIDGE_MSG, {friend: objData}));
				    break; 
			}
		}
		
		protected function get mainRoot():MainPage
		{
			return this.root as MainPage;
		}
	}
}